package com.qf.controller;

import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsStorage;
import com.qf.service.DtsStorageService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * 文件管理  存储对象管理  （阿里云 OSS  存储对象 )
 * @author lixu
 */
@RestController
@RequestMapping("/admin/storage")
@CrossOrigin
public class StorageController {

    @Autowired
    private DtsStorageService dtsStorageService;
    /**
     * 上传文件
     */
    @RequiresPermissionsDesc(menu = {"系统管理","对象存储"},button = "添加")
    @RequiresPermissions(value = {"admin:storage:create"})
    @PostMapping("/create")
    public Object create(MultipartFile file) throws Exception{

        //上传文件 并保存文件相关信息  再返回此存储对象
        DtsStorage dtsStorage = dtsStorageService.create(
                file.getBytes(),file.getOriginalFilename(),file.getSize());
        return ResponseUtil.ok(dtsStorage);
    }









}
